package com.zhuoyue.web.controller.system;

import com.zhuoyue.common.core.controller.BaseController;
import com.zhuoyue.common.core.domain.AjaxResult;
import com.zhuoyue.common.core.page.TableDataInfo;
import com.zhuoyue.common.utils.poi.ExcelUtil;
import com.zhuoyue.system.domain.ZigbeeDeviceLinkageRelation;
import com.zhuoyue.system.domain.vo.ZigbeeDeviceLinkageRelationVo;
import com.zhuoyue.system.service.IZigbeeDeviceLinkageRelationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 极享设备联动配置Controller
 *
 * @author zyzn
 * @date 2021-09-24
 */
@RestController
@RequestMapping("/system/relation/linkage")
public class ZigbeeDeviceLinkageRelationController extends BaseController {
    @Autowired
    private IZigbeeDeviceLinkageRelationService zigbeeDeviceLinkageRelationService;

    /**
     * 查询极享设备联动配置列表
     */
    @GetMapping("/list")
    public TableDataInfo list(ZigbeeDeviceLinkageRelation zigbeeDeviceLinkageRelation) {
        List<ZigbeeDeviceLinkageRelationVo> list = zigbeeDeviceLinkageRelationService.selectZigbeeDeviceLinkageRelationList(zigbeeDeviceLinkageRelation);
        return getDataTable(list);
    }

    /**
     * 导出极享设备联动配置列表
     */
    @GetMapping("/export")
    public AjaxResult export(ZigbeeDeviceLinkageRelation zigbeeDeviceLinkageRelation) {
        List<ZigbeeDeviceLinkageRelationVo> list = zigbeeDeviceLinkageRelationService.selectZigbeeDeviceLinkageRelationList(zigbeeDeviceLinkageRelation);
        ExcelUtil<ZigbeeDeviceLinkageRelationVo> util = new ExcelUtil<ZigbeeDeviceLinkageRelationVo>(ZigbeeDeviceLinkageRelationVo.class);
        return util.exportExcel(list, "联动");
    }

    /**
     * 获取极享设备联动配置详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return AjaxResult.success(zigbeeDeviceLinkageRelationService.selectZigbeeDeviceLinkageRelationById(id));
    }

    /**
     * 新增极享设备联动配置
     */
    @PostMapping
    public AjaxResult add(@RequestBody ZigbeeDeviceLinkageRelation zigbeeDeviceLinkageRelation) {
        return toAjax(zigbeeDeviceLinkageRelationService.insertZigbeeDeviceLinkageRelation(zigbeeDeviceLinkageRelation));
    }

    /**
     * 修改极享设备联动配置
     */
    @PutMapping
    public AjaxResult edit(@RequestBody ZigbeeDeviceLinkageRelation zigbeeDeviceLinkageRelation) {
        return toAjax(zigbeeDeviceLinkageRelationService.updateZigbeeDeviceLinkageRelation(zigbeeDeviceLinkageRelation));
    }

    /**
     * 删除极享设备联动配置
     */
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(zigbeeDeviceLinkageRelationService.deleteZigbeeDeviceLinkageRelationByIds(ids));
    }
}
